﻿#region 文档操作记录
// TblTimezone.cs
// 说明：
// 
// 创建日期：13:17
// 文档作者：饶杰
//  
// 更新日志：
#endregion

using System;
using System.Text;

namespace PullSdkHelper.Tables
{
    /// <summary>
    /// 时间段表
    /// </summary>
    public class TblTimezone
    {
        public class TimeRange
        {
            /// <summary>
            /// 8:30 → 8*100+30 
            /// </summary>
            /// <param name="begin"></param>
            /// <param name="end"></param>
            public TimeRange(int begin,int end)
            {
                this.Begin = begin;
                this.End = end;
            }
            public TimeRange(int timevalue)
            {
                var timeRange = timevalue.ToString("x8");
                var beginHex = timeRange.Substring(0, 4);
                var endHex = timeRange.Substring(4, 4);
                Begin = Int32.Parse(beginHex, System.Globalization.NumberStyles.HexNumber);
                End = Int32.Parse(endHex, System.Globalization.NumberStyles.HexNumber);
            }

            public int TimeValue
            {
                get
                {
                    var x16 = Begin.ToString("x8") + End.ToString("x8");
                    return Int32.Parse(x16, System.Globalization.NumberStyles.HexNumber);
                }
            }

            public int Begin { get;private set; }
            public int End { get; private set; }

            public string TimeRagneString { get; private set; }
            public override string ToString()
            {
                if (!string.IsNullOrEmpty(TimeRagneString))
                {
                    return TimeRagneString;
                }

                StringBuilder tRange = new StringBuilder(11);
               
                var hour = Begin/100;
                tRange.Append(hour.ToString().PadLeft(2, '0'));
                tRange.Append(':');
                var minute = Begin%100;
                tRange.Append(minute.ToString().PadLeft(2, '0'));

                tRange.Append('~');

                hour = End / 100;
                tRange.Append(hour.ToString().PadLeft(2, '0'));
                tRange.Append(':');
                minute = End % 100;
                tRange.Append(minute.ToString().PadLeft(2, '0'));

                return TimeRagneString = tRange.ToString();
            }
        }
        /// <summary>
        /// ID
        /// </summary>
        public int TimezoneId { get; set; }
        public TimeRange SunTime1 { get; set; }
        public TimeRange SunTime2 { get; set; }
        public TimeRange SunTime3 { get; set; }
        public TimeRange MonTime1 { get; set; }
        public TimeRange MonTime2 { get; set; }
        public TimeRange MonTime3 { get; set; }
        public TimeRange TueTime1 { get; set; }
        public TimeRange TueTime2 { get; set; }
        public TimeRange TueTime3 { get; set; }
        public TimeRange WedTime1 { get; set; }
        public TimeRange WedTime2 { get; set; }
        public TimeRange WedTime3 { get; set; }
        public TimeRange ThuTime1 { get; set; }
        public TimeRange ThuTime2 { get; set; }
        public TimeRange ThuTime3 { get; set; }
        public TimeRange FriTime1 { get; set; }
        public TimeRange FriTime2 { get; set; }
        public TimeRange FriTime3 { get; set; }
        public TimeRange SatTime1 { get; set; }
        public TimeRange SatTime2 { get; set; }
        public TimeRange SatTime3 { get; set; }
        public TimeRange Hol1Time1 { get; set; }
        public TimeRange Hol1Time2 { get; set; }
        public TimeRange Hol1Time3 { get; set; }
        public TimeRange Hol2Time1 { get; set; }
        public TimeRange Hol2Time2 { get; set; }
        public TimeRange Hol2Time3 { get; set; }
        public TimeRange Hol3Time1 { get; set; }
        public TimeRange Hol3Time2 { get; set; }
        public TimeRange Hol3Time3 { get; set; }
    }
}